package com.briup.mt.service.impl;

import com.briup.mt.bean.*;
import com.briup.mt.dao.BaseConfigMapper;
import com.briup.mt.dao.CategoryMapper;
import com.briup.mt.service.IBaseConfigService;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseConfigServiceImpl implements IBaseConfigService {

    @Resource
    private BaseConfigMapper baseConfigMapper;

    @Override
    public List<BaseConfig> query(String name) {

        BaseConfigExample baseConfigExample = new BaseConfigExample();
        if(!StringUtils.isEmpty(name)){
            baseConfigExample.createCriteria().andNameLike("%"+name+"%");
        }

        List<BaseConfig> list = baseConfigMapper.selectByExample(baseConfigExample);
        return list;
    }
    @Override
    public void saveOrUpdate(BaseConfig baseConfig) {
        if(baseConfig.getId() == null){
            baseConfigMapper.insert(baseConfig);
        } else {
            baseConfigMapper.updateByPrimaryKey(baseConfig);
        }
    }

    @Override
    public void deleteById(long id) {
        baseConfigMapper.deleteByPrimaryKey(id);

    }
}
